﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace telWebBrowserNet.Lib.TeleDLL.Model
{
    /// <summary>
    /// 读命令实体类
    /// </summary>
    public class ReadModel : TeleBaseModel
    {
        private string checksum;
        private string signal;
        private string sim;
        private string registed;
        private string callOutNumber;
        private string callerId;
        private string dtmf;
        private string smsCount;
        private string smsContent;
        private string station;
        private string writeFeedBack;

        private int teleReadCode;
        private int teleWriteCode;

        /// <summary>
        /// 信号
        /// </summary>
        public string Signal { get => signal; set => signal = value; }
        /// <summary>
        /// SIM卡状态
        /// </summary>
        public string Sim { get => sim; set => sim = value; }
        /// <summary>
        /// 注册状态
        /// </summary>
        public string Registed { get => registed; set => registed = value; }
        /// <summary>
        /// 打出的号码 最多32位
        /// </summary>
        public string CallOutNumber { get => callOutNumber; set => callOutNumber = value; }
        /// <summary>
        /// 
        /// </summary>
        public string CallerId { get => callerId; set => callerId = value; }
        /// <summary>
        /// 按键 通话中收到的 最多64位
        /// </summary>
        public string Dtmf { get => dtmf; set => dtmf = value; }
        /// <summary>
        /// 上报短信的个数
        /// </summary>
        public string SmsCount { get => smsCount; set => smsCount = value; }
        /// <summary>
        /// 上报短信内容
        /// </summary>
        public string SmsContent { get => smsContent; set => smsContent = value; }
        /// <summary>
        /// 电话盒子状态
        /// Station:Unknow;	当前状态：未知（重启动中）
            /*Station:PowerOning;	开机中
            Station:CallOutProgressing;	主叫呼叫中
            Station:CallOutCalledRing;	主叫呼出，被叫已接通，响铃中
            Station:CallOutNoAnswer;	主叫呼出，被叫未接听
            Station:CallOutFailed;	主叫呼叫失败
            Station:CallOutTalking;	主叫成功，通话中
            Station:CallInRing;	被叫响铃中
            Station:CallInTalking;	被叫接听中
            Station:HookOff;	摘机
            Station:HookOn;	挂机
            Station:SendSmsOk;	短信发送成功
            Station:SendSmsFailed;	短信发送失败
            Station:SendingSms;	短信发送中
            Station:ReadingSms;	读短信中
            Station:ReadSmsOk;	读短信完成
            Station:CallWaitingNumber:10086;	通话中的呼叫待号码，只上传一次
            Station:HandSetTalking;	手柄模式下电话机在通话中
            Station:HandSetRing;	手柄模式下电话机在响铃
            Station:SimSwitching;	换卡中*/
        /// </summary>
        public string Station { get => station; set => station = value; }
    
        /// <summary>
        /// 读接口错误码
        /// </summary>
        public int TeleReadCode { get => teleReadCode; set => teleReadCode = value; }
        /// <summary>
        /// 写接口错误码
        /// </summary>
        public int TeleWriteCode { get => teleWriteCode; set => teleWriteCode = value; }
        /// <summary>
        /// 校验和
        /// </summary>
        public string Checksum { get => checksum; set => checksum = value; }
        /// <summary>
        /// 原始读取的指令
        /// </summary>
        public string WriteFeedBack { get => writeFeedBack; set => writeFeedBack = value; }

        /// <summary>
        /// 实例化读取实体
        /// </summary>
        public ReadModel()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="feedback"></param>
        public void SetReadModel(string feedBack)
        {
            //LogInfo.LogOutput(LogInfo.log_info, "SetReadModel-top");
            //string feedBack = statusInfo.ToString();
            writeFeedBack = feedBack;
            Console.WriteLine("boxCommand:" + feedBack);
            feedBack = feedBack.Replace("adusun<", "").Replace(">end", "");
            string[] str = feedBack.Split(';');
            //adusun<Station:HookOn;Web:SdkIdel;Signal:4;Registed:OK;Sim:Ready;CurrentSim:5;CallOutNumber:;CallerId:;Dtmf:;SmsCount:005;ComId:00000;checksum:5F1FA6
            Dictionary<string, string> dicCommond = new Dictionary<string, string>();
            for (int i = 0; i < str.Length; i++)
            {
                string[] tempStr = str[i].Split(':');
                dicCommond[tempStr[0]] = tempStr[1];
            }
            SetReadModel(dicCommond);
            //LogInfo.LogOutput(LogInfo.log_info, "SetReadModel-bottom");
        }
        /// <summary>
        /// 设置readModel的内容
        /// </summary>
        /// <param name="readDic">命令键值对</param>
        public void SetReadModel(Dictionary<string, string> readDic)
        {
            foreach (string key in readDic.Keys)
            {
                switch (key.ToLower())
                {
                    case "signal":
                        this.signal = readDic[key];
                        break;
                    case "sim":
                        this.sim = readDic[key];
                        break;
                    case "registed":
                        this.registed = readDic[key];
                        break;
                    case "callOutNumber":
                        this.callOutNumber = readDic[key];
                        break;
                    case "callerId":
                        this.callerId = readDic[key];
                        break;
                    case "dtmf":
                        this.dtmf = readDic[key];
                        break;
                    case "smsCount":
                        this.smsCount = readDic[key];
                        break;
                    case "smsContent":
                        this.smsContent = readDic[key];
                        break;
                    case "station":
                        this.station = readDic[key];
                        break;
                    case "checksum":
                        this.checksum = readDic[key];
                        break;
                    case "code":
                        this.code = Convert.ToInt32(readDic[key]);
                        break;
                    case "teleReadCode":
                        this.teleReadCode = Convert.ToInt32(readDic[key]);
                        break;
                    case "teleWriteCode":
                        this.teleWriteCode = Convert.ToInt32(readDic[key]);
                        break;
                    default:
                        break;
                }//end switch
            }//end for
        }
    }
}
